# -*- codeing=utf-8 -*-

from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWidgets import QTabWidget
import sys


class MyPrograme(QMainWindow):
    def __init__(self):
        super(MyPrograme, self).__init__()
        self.initLogin()
        self.initMain()
        self.show()

    def initLogin(self):
        userStr = QLabel("用户：")
        pwdStr = QLabel("密码：")
        self.userInput = QLineEdit()
        self.userInput.setPlaceholderText("手机号/邮箱/用户名")
        self.userInput.setMaxLength(20)
        self.pwdInput = QLineEdit()
        self.pwdInput.setPlaceholderText("请输入密码")
        self.pwdInput.setMaxLength(20)
        self.pwdInput.setEchoMode(QLineEdit.Password)

        inputGridLayout = QGridLayout()
        inputGridLayout.addWidget(userStr, 0, 0, 1, 1)
        inputGridLayout.addWidget(self.userInput, 0, 1, 1, 1)
        inputGridLayout.addWidget(pwdStr, 1, 0, 1, 1)
        inputGridLayout.addWidget(self.pwdInput, 1, 1, 1, 1)

        okBtn = QPushButton("确定")
        okBtn.clicked.connect(self.accept)
        cancelBtn = QPushButton("取消")
        cancelBtn.clicked.connect(self.reject)

        btnLayout = QHBoxLayout()
        btnLayout.addWidget(okBtn)
        btnLayout.addWidget(cancelBtn)

        dlgLayout = QVBoxLayout()
        dlgLayout.addLayout(inputGridLayout)
        dlgLayout.addLayout(btnLayout)

        loginBox = QGroupBox("请先登录....")
        loginBox.setLayout(dlgLayout)

        loginLayout = QGridLayout()
        loginLayout.addWidget(loginBox)
        loginLayout.setContentsMargins(180, 180, 180, 150)

        self.loginMainWidget = QWidget()
        self.loginMainWidget.setLayout(loginLayout)

    def removeLogin(self):
        self.loginMainWidget.hide()

    def accept(self):
        if self.userInput.text().strip() == "hello" and self.pwdInput.text() == "hello":
            self.removeLogin()
            self.initMain()
            pass
        else:
            QMessageBox.warning(self, "警告", "用户名或密码错误！", QMessageBox.Yes)
            self.userInput.setFocus()

    def reject(self):
        exit()

    def initMain(self):
        self.setWindowTitle("主功能界面")
        self.tabWidget = QTabWidget()
        self.tabWidget.addTab(self.loginMainWidget,"登录")
        self.tabWidget.addTab(QWidget(),"表格")
        self.tabWidget.addTab(QWidget(),"支出")
        self.tabWidget.addTab(QWidget(),"合算")
        self.setCentralWidget(self.tabWidget)
        self.resize(600, 600)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyPrograme()
    sys.exit(app.exec_())
